package attribute;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-13
 * Time: 15:38
 */

//线程的阻塞等待 join
public class Demo3 {
    public static void main(String[] args) throws InterruptedException {
        //演示一下join用途   谁调用 谁阻塞
        Thread t1 = new Thread(() ->{
            while (true){
                System.out.println("Java");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        Thread t2 = new Thread(() ->{
            while (true){
                System.out.println("C++");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t2.start();

        t1.join(7000);
        return;

    }
}
